package Aptech.Service;

import java.util.Iterator;
import java.util.List;

import Aptech.DAL.MgContract;
import Aptech.DAL.MgOrder;
import HibernateMappingPoJo.Orders;
import HibernateMappingPoJo.PurchaseContract;

public class SV_Order {
	private MgOrder mgOrder ;
	private MgContract mgContract;
	public SV_Order(){
		mgOrder = new MgOrder();
		mgContract= new MgContract();
	}
	
	public Orders[] getAllOder(){
		 List<Orders>  list = mgOrder.getAllOder();
		 String name = "";
		 Orders[] listBuilts = new Orders[list.size()];
	        if (list != null) {
	            Iterator<Orders> iter = list.iterator();
	            int i = 0;
	            while (iter.hasNext()) {
	            	Orders tptd = (Orders) iter.next();
	            	name = mgContract.getContractByID(tptd.getIdContract()).getContractNumber();
	            	tptd.setIdContract(name);
	                listBuilts[i] = tptd;
	                i++;
	            }
	        }
	        return listBuilts;
	}
	public void addOrder(Orders order){
		mgOrder.addOrder(order);
	}
	
	public void deleteOrder(String id){
		mgOrder.deleteOrder(id);
	}
	public void editOrder(Orders order){
		mgOrder.editOrder(order);
	}

	public Orders getOrderByID(String id){
		return mgOrder.getOrderByID(id);
	}
}
